<?php

if ( ! class_exists( 'WP_List_Table' ) )
	require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

class P2C_ProjectData_List_Table extends WP_List_Table {

	function __construct() {
		parent::__construct( array(
			'singular' => 'projectdata',
			'plural' => 'projectdata',
			'ajax' => false ) );
	}

	function prepare_items( $projectid = 0) {
		$columns = $this->get_columns();
		$per_page = 20;

		$hidden = array();
        $sortable = array();
        $this->_column_headers = array($columns, $hidden, $sortable);
        
		$args = array(
			'posts_per_page' => $per_page,
			'orderby' => 'start_date',
			'order' => 'DESC',
			'offset' => ( $this->get_pagenum() - 1 ) * $per_page ,
            'projectid' => $projectid );

		$this->items = P2C_ProjectData::find( $args );

		$total_items = P2C_ProjectData::rowcount( $projectid );
		$total_pages = ceil( $total_items / $per_page );
        
		$this->set_pagination_args( array(
			'total_items' => $total_items,
			'total_pages' => $total_pages,
			'per_page' => $per_page ) );
	}

	function get_columns() {
        $columns = array(
			//'cb' => '<input type="checkbox" />',
			'start_date' => __( 'Start Date', 'p2c_admin' ),
            'end_date' => __( 'End Date', 'p2c_admin' ),
			'target' => __( 'Target', 'p2c_admin' ),
            'current' => __( 'Current', 'p2c_admin' ),
			'days_remaining' => __( 'Days Remaining', 'p2c_admin' ));

		return $columns;
	}

	function get_bulk_actions() {
		$actions = array();
			//'delete' => __( 'Delete', 'p2c_admin' ) );

		return $actions;
	}

	function column_default( $item, $column_name ) {
		return '';
    }

//	function column_cb( $item ) {
//		return sprintf(
//			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
//			$this->_args['singular'],
//			$item->id );
//	}

    function column_start_date( $item ) {
         return $item->start_date;
    }
    
    function column_end_date( $item ) {
         return $item->end_date;
    }
    
    function column_target( $item ) {
         return $item->target;
    }
    
	function column_current( $item ) {
         return $item->current;
    }
    
    function column_days_remaining( $item ) {
        return $item->days_remaining;
	}

}

?>